package filter

import (
	"net/http"

	"github.com/astaxie/beego/context"
	"strings"
)

func UserFilter(ctx *context.Context) {
	if strings.HasPrefix(ctx.Request.RequestURI, "/api") ||
		strings.HasPrefix(ctx.Request.RequestURI, "/login") ||
		strings.HasPrefix(ctx.Request.RequestURI, "/logout") ||
		ctx.Request.RequestURI == "/" {
		return
	}

	id, ok := ctx.Input.CruSession.Get("id").(string)
	if !ok || id == "" {
		ctx.ResponseWriter.WriteHeader(http.StatusUnauthorized)
	}
}
